<?php
defined ( 'BASEPATH' ) or exit ( 'No direct script access allowed' );
date_default_timezone_set ( 'prc' );
class Common{
	public function __construct() {
        $this->ci = &get_instance();
    }
	/*
	 * 返回可订餐日期
	 */
	public function getOrderDate($schoolid){
		$orderdate=array();
		$sdate = getSdate();//下周二
		$edate = getEdate();//下下周一
		$this->ci->load->model ( 'product_model' );
		//$this->ci->load->model ( 'orderdate_model' );
		for($start = strtotime($sdate); $start <= strtotime($edate);$start += 3600*24){
			/*
			if(date('w',$start)>=1&&date('w',$start)<=5){
				$orderdate1=$this->ci->orderdate_model->find_by_date(date('Y-m-d',$start),1);//查找不可以订餐日期
				if(!empty($orderdate1)){
					continue;
				}
			}
			if(date('w',$start)==0||date('w',$start)==6){
				$orderdate2=$this->ci->orderdate_model->find_by_date(date('Y-m-d',$start),0);//查找可以订餐日期
				if(empty($orderdate2)){
					continue;
				}
			}*/
			$date=date ( "Y-m-d", $start);
			$num = $this->ci->product_model->count_by_school_date_type ($schoolid,$date,-1);
			if(empty($num)){
				continue;
			}
			$orderdate[]=date('Y-m-d',$start);
		}
		return $orderdate;
	}
	
	
	public function isOrder($userid){
		$enddate=date('Y-m-d');
		if(date('w')==0){
			$startdate=date('Y-m-d');
		}else{
			$startdate=date('Y-m-d', (time() - date('w') * 24 * 3600));
		}
		$this->ci->load->model ( 'order_model' );
		$order = $this->ci->order_model->find_by_user_date ($userid,$startdate,$enddate);
		if(!empty($order)){
			return TRUE;
		}else{
			return FALSE;
		}
	}
}